home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / WINDOWS / WZUN11SR.ARJ / WNDPROC.C < prev   
C/C++ Source or Header  |  1992-01-24  |  23KB  |  681 lines

  1. #include <sys\types.h>
  2. #include <sys\stat.h>
  3. #include <time.h>                
  4. #include <string.h>             
  5. #include <windows.h>    /* required for all Windows applications */
  6. #include <assert.h>    /* required for all Windows applications */
  7. #include "wizunzip.h"                /* specific to this program              */
  8. #include "helpids.h"
  9.  
  10. /* Windows Info-ZIP Unzip Window Procedure, wndproc.c.
  11.  * Author: Robert A. Heath, 157 Chartwell Rd., Columbia, SC 29210
  12.  * I, Robert Heath, place this source code module in the public domain.
  13.  */
  14.  
  15. #define BUTTON_CHARS        16    /* button width in chars        */
  16. #define STATUS_ROWS 6
  17. #define BUTTONS_ROW  16
  18.  
  19.  
  20. static char FormatKeyword[2][6] = { "short", "long" };
  21.  
  22. char szHelpFileName[] = "WIZUNZIP.HLP";
  23.  
  24. short xchar, ychar;    /* size of char in SYSTEM font in pixels    */
  25.  
  26. /* button control table    -- one entry for 
  27.  * each of 4 entries. Indexed by the window ID relative to
  28.  * the first tabstop (TABSTOP_ID_BASE).            
  29.  */
  30. TabStopEntry TabStopTable[TABSTOP_TABLE_ENTRIES]; 
  31.  
  32.  
  33. /****************************************************************************
  34.  
  35.     FUNCTION: WizunzipWndProc(HWND, unsigned, WORD, LONG)
  36.  
  37.     PURPOSE:  Processes messages
  38.  
  39.     MESSAGES:
  40.  
  41.     WM_DESTROY    - destroy window
  42.     WM_SIZE          - window size has changed
  43.     WM_QUERYENDSESSION - willing to end session?
  44.     WM_ENDSESSION - end Windows session
  45.     WM_CLOSE      - close the window
  46.     WM_SIZE          - window resized
  47.  
  48.     COMMENTS:
  49.  
  50.     WM_COMMAND processing:
  51.  
  52.         IDM_OPEN -  open a new file.
  53.  
  54.  
  55.         IDM_EXIT - query to save current file if there is one and it
  56.                has been changed, then exit.
  57.  
  58.         IDM_ABOUT - display "About" box.
  59.  
  60. ****************************************************************************/
  61.  
  62. long FAR PASCAL WizunzipWndProc(hWnd, message, wParam, lParam)
  63. HWND hWnd;
  64. unsigned message;
  65. WORD wParam;
  66. LONG lParam;
  67. {
  68.  
  69.     FARPROC lpProcAbout, lpProcFileDlg, lpProcChDir;
  70.  
  71.     HDC hDC;                /* device context         */
  72.     TEXTMETRIC      tm;            /* text metric structure    */
  73. static WORD  wButtonWidth ;
  74. static WORD xScreen, yScreen;
  75. POINT point;
  76. BOOL FileDlgRetVal;
  77. FARPROC lpfnKbdProc;
  78.    DWORD   dwHelpContextId;    /* help context ID            */
  79. char szBuffer[100];
  80.  
  81.  
  82.     switch (message) {
  83.     case WM_CREATE:    /* create  window        */
  84.             xScreen = GetSystemMetrics(SM_CXSCREEN);
  85.             yScreen = GetSystemMetrics(SM_CYSCREEN);
  86.             hInst = ((LPCREATESTRUCT)lParam)->hInstance;
  87.             lpfnKbdProc = MakeProcInstance((FARPROC)KbdProc, hInst);
  88.             hAccTable = LoadAccelerators(hInst, "WizunzipAccels");
  89.             hBrush = CreateSolidBrush(GetSysColor(BG_SYS_COLOR)); /* background */
  90.  
  91.             hMenu = GetMenu(hWnd);        /* get menu handle             */
  92.             /* Check Menu items to reflect WIN.INI settings
  93.              */
  94.             CheckMenuItem(hMenu, IDM_RECR_DIR_STRUCT, MF_BYCOMMAND| 
  95.                             (WORD)(bRecreateDirs ? MF_CHECKED : MF_UNCHECKED));
  96.             CheckMenuItem(hMenu, (IDM_SHORT+wFormat), MF_BYCOMMAND|MF_CHECKED);
  97.             CheckMenuItem(hMenu,IDM_OVERWRITE,MF_BYCOMMAND|
  98.                                 (WORD)(bOverwrite ? MF_CHECKED:MF_UNCHECKED));
  99.             CheckMenuItem(hMenu,IDM_TRANSLATE,MF_BYCOMMAND|
  100.                                 (WORD)(bTranslate ? MF_CHECKED:MF_UNCHECKED));
  101.             CheckMenuItem(hMenu,wLBSelection,MF_BYCOMMAND|MF_CHECKED);
  102.             CheckMenuItem(hMenu,IDM_UNZIP_TO_ZIP_DIR,MF_BYCOMMAND|
  103.                                 (WORD)(bUnzipToZipDir ? MF_CHECKED:MF_UNCHECKED));
  104.             EnableMenuItem(hMenu,IDM_CHDIR,MF_BYCOMMAND|
  105.                                 (WORD)(bUnzipToZipDir ? MF_GRAYED:MF_ENABLED));
  106.              /* Get an hourglass cursor to use during file transfers */
  107.  
  108.             hHourGlass = LoadCursor(NULL, IDC_WAIT);
  109.               hFixedFont = GetStockObject(SYSTEM_FIXED_FONT);
  110.         hDC = GetDC(hWnd);    /* get device context */
  111.           hOldFont   = SelectObject ( hDC, hFixedFont);
  112.         GetTextMetrics(hDC, &tm);
  113.         ReleaseDC(hWnd, hDC);
  114.         xchar = tm.tmAveCharWidth;
  115.         ychar = tm.tmHeight + tm.tmExternalLeading; 
  116.         wButtonWidth = BUTTON_CHARS* xchar;
  117.  
  118.         hWndHeaderLine1 = CreateWindow("static", "Header Line1",
  119.                 WS_CHILD|WS_VISIBLE|SS_LEFT,
  120.                 0, 0,
  121.                 sizeof("Header Line2"), ychar,
  122.                 hWnd, IDM_HEADER_LINE1,
  123.                 GetWindowWord (hWnd, GWW_HINSTANCE), NULL);
  124.         SendMessage(hWndHeaderLine1,  WM_SETFONT,  hFixedFont , TRUE);
  125.  
  126.         hWndHeaderLine2 = CreateWindow("static", "Header Line2",
  127.                 WS_CHILD|WS_VISIBLE|SS_LEFT,
  128.                 0, ychar,
  129.                 sizeof("Header Line2"), ychar,
  130.                 hWnd, IDM_HEADER_LINE1,
  131.                 GetWindowWord (hWnd, GWW_HINSTANCE), NULL);
  132.         SendMessage(hWndHeaderLine2,  WM_SETFONT,  hFixedFont , TRUE);
  133.  
  134.         hWndList = CreateWindow("listbox", NULL,
  135.                 WS_CHILD|WS_VISIBLE| LBS_NOTIFY | WS_VSCROLL| WS_BORDER|
  136.                 LBS_EXTENDEDSEL,
  137.                 0, 2*ychar,
  138.                 40*xchar, 16*ychar,
  139.                 hWnd, IDM_LISTBOX,
  140.                 GetWindowWord (hWnd, GWW_HINSTANCE), NULL);
  141.         MAKE_TABSTOP_TABLE_ENTRY(hWndList, IDM_LISTBOX);
  142.         SendMessage(hWndList,  WM_SETFONT,  hFixedFont , FALSE);
  143.         ShowWindow(hWndList, SW_SHOW);
  144.         UpdateWindow(hWndList);            /* show it now!                */
  145.  
  146.         hWndTotalLine1 = CreateWindow("static", "",
  147.                 WS_CHILD|WS_VISIBLE|SS_LEFT,
  148.                 0, 19*ychar,
  149.                 0, ychar,
  150.                 hWnd, IDM_TOTAL_LINE1,
  151.                 GetWindowWord (hWnd, GWW_HINSTANCE), NULL);
  152.         SendMessage(hWndTotalLine1,  WM_SETFONT,  hFixedFont , TRUE);
  153.  
  154.         hWndTotalLine2 = CreateWindow("static", "",
  155.                 WS_CHILD|WS_VISIBLE|SS_LEFT,
  156.                 0, 20*ychar,
  157.                 0, ychar,
  158.                 hWnd, IDM_TOTAL_LINE2,
  159.                 GetWindowWord (hWnd, GWW_HINSTANCE), NULL);
  160.         SendMessage(hWndTotalLine2,  WM_SETFONT,  hFixedFont , TRUE);
  161.  
  162.         hWndStatus = CreateWindow(szStatusClass, "Messages",
  163.                 WS_CHILD|WS_SYSMENU|WS_VISIBLE|WS_BORDER|WS_HSCROLL|WS_VSCROLL|WS_MAXIMIZEBOX|WS_CAPTION,
  164.                 0, 21*ychar,
  165.                 0, STATUS_ROWS * ychar,
  166.                 hWnd, IDM_STATUS,
  167.                 GetWindowWord (hWnd, GWW_HINSTANCE), NULL);
  168.         SendMessage(hWndStatus,  WM_SETFONT,  hFixedFont , TRUE);
  169.         MAKE_TABSTOP_TABLE_ENTRY(hWndStatus, IDM_STATUS);
  170.  
  171.  
  172.         hExtract = CreateWindow("button", "E&xtract",  
  173.                     WS_CHILD | BS_PUSHBUTTON,
  174.                     0,      
  175.                     ychar * BUTTONS_ROW,
  176.                     BUTTON_CHARS * xchar,   2 * ychar,
  177.                     hWnd, IDM_EXTRACT,
  178.                     hInst,
  179.                     NULL);
  180.         ShowWindow(hExtract, SW_SHOW);
  181.         MAKE_TABSTOP_TABLE_ENTRY(hExtract, IDM_EXTRACT);
  182.  
  183.  
  184.         hDisplay= CreateWindow("button", "&Display",                      
  185.                     WS_CHILD | BS_PUSHBUTTON,
  186.                     0,      
  187.                     ychar * BUTTONS_ROW,
  188.                     BUTTON_CHARS * xchar,   2 * ychar,
  189.                     hWnd, IDM_DISPLAY,
  190.                     hInst,
  191.                     NULL);
  192.         ShowWindow(hDisplay, SW_SHOW);
  193.         MAKE_TABSTOP_TABLE_ENTRY(hDisplay, IDM_DISPLAY);
  194.  
  195.         hTest= CreateWindow("button", "&Test",          
  196.                     WS_CHILD | BS_PUSHBUTTON,
  197.                     0,      
  198.                     ychar  * BUTTONS_ROW,
  199.                     BUTTON_CHARS * xchar,   2 * ychar,
  200.                     hWnd, IDM_TEST,
  201.                     hInst,
  202.                     NULL);
  203.         ShowWindow(hTest, SW_SHOW);
  204.         MAKE_TABSTOP_TABLE_ENTRY(hTest, IDM_TEST);
  205.     
  206.  
  207.         hShowComment= CreateWindow("button", "&Show Comment",  WS_CHILD  |
  208.                     BS_PUSHBUTTON,
  209.                     0,      
  210.                     ychar  * BUTTONS_ROW,
  211.                     BUTTON_CHARS * xchar,   2 * ychar,
  212.                     hWnd, IDM_SHOW_COMMENT,
  213.                     hInst,
  214.                     NULL);
  215.         ShowWindow(hShowComment, SW_SHOW);
  216.         MAKE_TABSTOP_TABLE_ENTRY(hShowComment, IDM_SHOW_COMMENT);
  217.  
  218.         if (szFileName[0])        /* if file spec'd on entry */
  219.         {
  220.         char *pC;
  221.         extern int ofretval; /* return value from initial open if filename given
  222.                                 during WinMain()                 */
  223.  
  224.  
  225.             OemToAnsi(szFileName, szBuffer); /* translate to ANSI */
  226.             /* If valid filename change dir to where it lives    */
  227.              if (ofretval >= 0)
  228.             {
  229.                 if ((pC = strrchr(szBuffer, '\\')) ||
  230.                         (pC = strrchr(szBuffer, ':')))
  231.                     *pC = '\0'; /* take only path portion        */
  232.  
  233.                 strcpy(szOrigDirName, szBuffer);    /* save current dir    */
  234.                 DlgDirList(hWnd, szBuffer, 0, 0, 0);
  235.             }
  236.             else /* bad file name    */
  237.             {
  238.                 if ((pC = strrchr(szBuffer, '\\')) ||
  239.                         (pC = strrchr(szBuffer, ':')))
  240.                     pC++;    /* point to filename                */
  241.  
  242.                 else
  243.                     pC = szBuffer;
  244.     
  245.                 wsprintf (szBuffer, "Cannot open %s", (LPSTR)pC);
  246.                 MessageBox (hWnd, szBuffer, szAppName, MB_ICONINFORMATION | MB_OK);
  247.                 szFileName[0] = '\0'; /* pretend filename doesn't exist    */
  248.  
  249.             }
  250.         }
  251.         DoCaption(hWnd, szFileName);    /* put name in title bar    */
  252.         UpdateListBox(hWnd); /* fill in list box */
  253.         UpdateButtons(hWnd);        /* update state of buttons    */
  254.         SizeWindow(hWnd, TRUE);    /* move things around as necessary    */
  255.  
  256.         break;
  257.     case WM_SETFOCUS:    /* hand off focus to child window        */
  258.         if (bStatusMaxed)    /* if message window is max'd        */
  259.             SetFocus(hWndStatus); /* pass focus to Messages Window    */
  260.  
  261.         else    /* list box gets it                                */
  262.             SetFocus(hWndList); /* pass focus to list box            */
  263.  
  264.         break;
  265.     case WM_ACTIVATE:                /* getting focus, max'ing, min'ing */
  266.         DoCaption(hWnd, szFileName);    /* put name in title bar    */
  267.         return DefWindowProc(hWnd, message, wParam, lParam);
  268.         break;
  269.     case WM_SIZE:  /* resize text and listbox to fix new window */
  270.         SizeWindow(hWnd, FALSE);    /* move things around as necessary    */
  271.         break;
  272.     case WM_CTLCOLOR: /* color background of buttons and statics */
  273.         if (HIWORD(lParam) == CTLCOLOR_STATIC)
  274.         {
  275.             SetBkMode(wParam, TRANSPARENT);
  276.             SetBkColor(wParam, GetSysColor(BG_SYS_COLOR)); /* custom b.g. color */
  277.             SetTextColor(wParam, GetSysColor(COLOR_WINDOWTEXT));
  278.             UnrealizeObject(hBrush);
  279.             point.x = point.y = 0;
  280.             ClientToScreen(hWnd, &point);
  281.             SetBrushOrg(wParam, point.x, point.y);
  282.             return((DWORD)hBrush);
  283.         }
  284.         else
  285.             return DefWindowProc(hWnd, message, wParam, lParam);
  286.  
  287.         break;
  288.     case WM_SYSCOMMAND:
  289.         /* process sub-message */
  290.         switch( wParam )
  291.             {
  292.         default :
  293.             return(DefWindowProc( hWnd, message, wParam, lParam ));
  294.             break;
  295.         }        
  296.         break;
  297.     case WM_COMMAND:
  298.            /* Was F1 just pressed in a menu, or are we in help mode */
  299.            /* (Shift-F1)? */
  300.  
  301.            if (bHelp) {
  302.                dwHelpContextId =
  303.                    (wParam == IDM_OPEN)   ? (DWORD) HELPID_OPEN    :
  304.                    (wParam == IDM_EXIT)   ? (DWORD) HELPID_EXIT_CMD    :
  305.                    (wParam == IDM_CHDIR)   ? (DWORD) HELPID_CHDIR    :
  306.                    (wParam == IDM_SHORT)   ? (DWORD) HELPID_SHORT    :
  307.                    (wParam == IDM_LONG)    ? (DWORD) HELPID_LONG     :
  308.                    (wParam == IDM_HELP)  ? (DWORD) HELPID_HELP   :
  309.                    (wParam == IDM_HELP_HELP)  ? (DWORD) HELPID_HELP_HELP   :
  310.                    (wParam == IDM_ABOUT)   ? (DWORD) HELPID_ABOUT    :
  311.                    (wParam == IDM_RECR_DIR_STRUCT)   ? (DWORD) HELPID_RECR_DIR_STRUCT :
  312.                    (wParam == IDM_OVERWRITE)   ? (DWORD) HELPID_OVERWRITE :
  313.                    (wParam == IDM_TRANSLATE)   ? (DWORD) HELPID_TRANSLATE :
  314.                    (wParam == IDM_UNZIP_TO_ZIP_DIR)   ? (DWORD) HELPID_UNZIP_TO_ZIP_DIR :
  315.                    (wParam == IDM_LISTBOX)   ? (DWORD) HELPID_LISTBOX :
  316.                    (wParam == IDM_EXTRACT)   ? (DWORD) HELPID_EXTRACT :
  317.                    (wParam == IDM_DISPLAY)   ? (DWORD) HELPID_DISPLAY :
  318.                    (wParam == IDM_TEST)   ? (DWORD) HELPID_TEST :
  319.                    (wParam == IDM_SHOW_COMMENT)   ? (DWORD) HELPID_SHOW_COMMENT :
  320.                    (wParam == IDM_LB_EXTRACT)   ? (DWORD) HELPID_LB_EXTRACT :
  321.                    (wParam == IDM_LB_DISPLAY)   ? (DWORD) HELPID_LB_DISPLAY :
  322.                    (wParam == IDM_LB_TEST)   ? (DWORD) HELPID_LB_TEST :
  323.                    (wParam == IDM_DESELECT_ALL)   ? (DWORD) HELPID_DESELECT_ALL :
  324.                    (wParam == IDM_SELECT_ALL)   ? (DWORD) HELPID_SELECT_ALL :
  325.                    (wParam == IDM_CLEAR_STATUS)   ? (DWORD) HELPID_CLEAR_STATUS :
  326.                                                            (DWORD) 0L;
  327.  
  328.                if (!dwHelpContextId)
  329.            {
  330.                    MessageBox( hWnd, "Help not available for Help Menu item",
  331.                    "Help Example", MB_OK                          );
  332.                    return (DefWindowProc(hWnd, message, wParam, lParam));
  333.            }
  334.  
  335.                bHelp = FALSE;
  336.                WinHelp(hWnd,szHelpFileName,HELP_CONTEXT,dwHelpContextId);
  337.         }
  338.         else /* not in help mode                                    */
  339.         {
  340.         switch (wParam) {
  341.         case IDM_OPEN:
  342.             /* If unzipping separately and previous file exists,
  343.              * go to directory where archive lives.
  344.              */
  345.             if (!bUnzipToZipDir && szFileName[0])
  346.             {
  347.                 PSTR lastchar;
  348.  
  349.                 OemToAnsi(szFileName, szBuffer); /* get scratch copy */
  350.                 /* strip off filename to make directory name    */
  351.                 if ((lastchar = strrchr(szBuffer, '\\')) ||
  352.                     (lastchar = strrchr(szBuffer, ':')))
  353.                         *lastchar = '\0';
  354.  
  355.                 DlgDirList (hWnd, szBuffer, 0, 0, 0); /* change dir */
  356.             }
  357.             lpProcFileDlg = MakeProcInstance(FileDlgProc, hInst);
  358.             FileDlgRetVal = 
  359.                         DialogBox(hInst, "FileDlg", hWnd, lpProcFileDlg);
  360.             FreeProcInstance(lpProcFileDlg);
  361.             if (FileDlgRetVal)    /* if successful file open            */
  362.             {
  363.                 /* If directory follows .ZIP or 1st open            */
  364.                 if (bUnzipToZipDir || !szOrigDirName[0])
  365.                 {
  366.                 PSTR lastchar;
  367.  
  368.                     /* strip off filename to make directory name    */
  369.                     OemToAnsi(szFileName, szOrigDirName);
  370.                     if ((lastchar = strrchr(szOrigDirName, '\\')) ||
  371.                         (lastchar = strrchr(szOrigDirName, ':')))
  372.                         *lastchar = '\0';
  373.  
  374.                 }
  375.                 UpdateListBox(hWnd);         /* fill in list box */
  376.                 UpdateButtons(hWnd);        /* update state of buttons    */
  377.             }
  378.             if (szOrigDirName[0]) /* if directory name exists, go there    */
  379.             {
  380.                 strcpy(szBuffer, szOrigDirName); /* get scratch copy */
  381.                 DlgDirList (hWnd, szBuffer, 0, 0, 0); /* change dir */
  382.             }
  383.             DoCaption(hWnd, szFileName);
  384.             break;
  385.         case IDM_CHDIR:
  386.             lpProcChDir = MakeProcInstance(ChDirProc, hInst);
  387.             (void)DialogBox(hInst, "ChDirDlg", hWnd, lpProcChDir);
  388.             FreeProcInstance(lpProcChDir);
  389.             break;
  390.  
  391.         case IDM_EXIT:
  392.             SendMessage(hWnd, WM_CLOSE, 0, 0L);
  393.                         break;
  394.  
  395.         case IDM_HELP:    /* Display Help                            */
  396.             WinHelp(hWnd,szHelpFileName,HELP_INDEX,0L);
  397.  
  398.             break;
  399.         case IDM_HELP_HELP:
  400.            WinHelp(hWnd,"WINHELP.HLP",HELP_INDEX,0L);
  401.                    break;
  402.         case IDM_ABOUT:
  403.             lpProcAbout = MakeProcInstance(About, hInst);
  404.             DialogBox(hInst, "About", hWnd, lpProcAbout);
  405.             FreeProcInstance(lpProcAbout);
  406.             break;
  407.         case IDM_LISTBOX:        /* command from listbox        */
  408.             if (TotalZippedFiles)            /* if any entries    */
  409.             {
  410.                 switch (HIWORD(lParam)) {
  411.                 case LBN_SELCHANGE:
  412.                     UpdateButtons(hWnd);
  413.                     break;
  414.                 case LBN_DBLCLK: /* double click action */
  415.                     UpdateButtons(hWnd);
  416.                     Action(wLBSelection - IDM_LB_EXTRACT);     /* do action    */
  417.                     break;
  418.                 }
  419.             }
  420.             break;
  421.         case IDM_LONG:    /* long version                            */
  422.         case IDM_SHORT:    /* short version                        */
  423.             { 
  424.                 WORD wFormatTmp = wParam - IDM_SHORT;
  425.                 int *pnSelItems;            /* pointer to list of selected items    */
  426.                 int    nSelCount ;                /* no. selected items in listbox */
  427.  
  428.  
  429.                 /* If format change, uncheck old, check new.
  430.                  */
  431.                 if (wFormatTmp != wFormat)    /* if format change        */
  432.                 {
  433.                     nSelCount = GetLBSelCount(hWndList, &pnSelItems);
  434.                     CheckMenuItem(hMenu, (IDM_SHORT+wFormat), MF_BYCOMMAND|MF_UNCHECKED);
  435.                     CheckMenuItem(hMenu, (IDM_SHORT+wFormatTmp), MF_BYCOMMAND|MF_CHECKED);
  436.                     wFormat = wFormatTmp;
  437.                     UpdateListBox(hWnd); /* fill list box                */
  438.                     SizeWindow(hWnd, TRUE);    /* move things around as necessary    */
  439.                     WriteProfileString(szAppName, FORMAT_KEY, 
  440.                                         (LPSTR)(FormatKeyword[wFormat]));
  441.                     if (nSelCount > 0)    /* anything previously selected ? */
  442.                     {
  443.                         ReselectLB(hWndList, nSelCount, pnSelItems);
  444.                         pnSelItems = (int *)LocalFree((HANDLE)pnSelItems); /* free it to Windows */
  445.                         assert(!pnSelItems);    /* DEBUG */
  446.                     }
  447.                     UpdateButtons(hWnd); /* enable or disable buttons */
  448.                 }
  449.             }
  450.             break;
  451.         case IDM_OVERWRITE:
  452.             { 
  453.  
  454.                 /* Toggle value of overwrite flag.
  455.                  */
  456.                 bOverwrite = !bOverwrite;
  457.                 CheckMenuItem(hMenu,IDM_OVERWRITE,MF_BYCOMMAND|
  458.                                 (WORD)(bOverwrite ? MF_CHECKED: MF_UNCHECKED));
  459.                 WriteProfileString(szAppName, OVERWRITE_KEY, 
  460.                         (LPSTR)(bOverwrite ? "yes" : "no" ));
  461.             }
  462.             break;
  463.         case IDM_TRANSLATE:
  464.             { 
  465.  
  466.                 /* Toggle value of translate flag.
  467.                  */
  468.                 bTranslate = !bTranslate;
  469.                 CheckMenuItem(hMenu,IDM_TRANSLATE,MF_BYCOMMAND|
  470.                                 (WORD)(bTranslate ? MF_CHECKED: MF_UNCHECKED));
  471.                 WriteProfileString(szAppName, TRANSLATE_KEY, 
  472.                         (LPSTR)(bTranslate ? "yes" : "no" ));
  473.             }
  474.             break;
  475.         case IDM_UNZIP_TO_ZIP_DIR: /* toggle value of Unzip to .ZIP  */
  476.             bUnzipToZipDir = !bUnzipToZipDir;
  477.             CheckMenuItem(hMenu,IDM_UNZIP_TO_ZIP_DIR,MF_BYCOMMAND|
  478.                                 (WORD)(bUnzipToZipDir ? MF_CHECKED:MF_UNCHECKED));
  479.             EnableMenuItem(hMenu,IDM_CHDIR,MF_BYCOMMAND|
  480.                                 (WORD)(bUnzipToZipDir ? MF_GRAYED:MF_ENABLED));
  481.             WriteProfileString(szAppName, UNZIP_TO_ZIP_DIR_KEY, 
  482.                         (LPSTR)(bUnzipToZipDir ? "yes" : "no" ));
  483.  
  484.             if (bUnzipToZipDir && szFileName[0])
  485.             {
  486.                 PSTR lastchar;
  487.  
  488.                 /* strip off filename to make directory name    */
  489.                 OemToAnsi(szFileName, szOrigDirName);
  490.                 if ((lastchar = strrchr(szOrigDirName, '\\')) ||
  491.                     (lastchar = strrchr(szOrigDirName, ':')))
  492.                     *lastchar = '\0';
  493.  
  494.                 if (szOrigDirName[0]) /* if directory name exists, go there    */
  495.                 {
  496.                     strcpy(szBuffer, szOrigDirName); /* get scratch copy */
  497.                        DlgDirList (hWnd, szBuffer, 0, 0, 0); /* change dir */
  498.                 }
  499.                 DoCaption(hWnd, szFileName);
  500.             }
  501.             break;
  502.         case IDM_LB_EXTRACT:
  503.         case IDM_LB_DISPLAY:
  504.         case IDM_LB_TEST:
  505.             { 
  506.                 WORD wLBSelectionTmp = wParam; 
  507.  
  508.                 /* If overwrite change, uncheck old, check new.
  509.                  */
  510.                 if (wLBSelectionTmp != wLBSelection)    /* if format change        */
  511.                 {
  512.  
  513.                     CheckMenuItem(hMenu,wLBSelection,MF_BYCOMMAND|MF_UNCHECKED);
  514.  
  515.                     CheckMenuItem(hMenu,wLBSelectionTmp,MF_BYCOMMAND|MF_CHECKED);
  516.  
  517.                     wLBSelection = wLBSelectionTmp;
  518.                     WriteProfileString(szAppName, LBSELECTION_KEY, 
  519.                         (LPSTR)(LBSelectionTable[wParam - IDM_LB_EXTRACT]));
  520.                 }
  521.             }
  522.             break;
  523.         case IDM_SHOW_COMMENT:    /* display the archive comment in mesg window */
  524.             DisplayComment();
  525.             break;
  526.         case IDM_RECR_DIR_STRUCT:    /* re-create directories structure */
  527.             bRecreateDirs = !bRecreateDirs;    /* toggle state            */
  528.             CheckMenuItem(hMenu, IDM_RECR_DIR_STRUCT, 
  529.              MF_BYCOMMAND| (WORD)(bRecreateDirs ? MF_CHECKED : MF_UNCHECKED));
  530.             WriteProfileString(szAppName, RECREATE_DIRS_KEY, 
  531.                                 (LPSTR)(bRecreateDirs ? "yes" : "no"));
  532.             break;
  533.         case IDM_DISPLAY:
  534.         case IDM_TEST:
  535.         case IDM_EXTRACT:
  536.             Action(wParam - IDM_EXTRACT);    /* Action() does it all    */
  537.             break;
  538.         case IDM_SELECT_ALL:
  539.         case IDM_DESELECT_ALL:
  540.             {
  541.  
  542.                 if (TotalZippedFiles) /* total listbox entries            */
  543.                 {
  544.                     SendMessage(hWndList , LB_SELITEMRANGE, 
  545.                             (WORD)(wParam == IDM_DESELECT_ALL ? FALSE : TRUE),
  546.                                 MAKELONG(0, (TotalZippedFiles-1)));
  547.                     UpdateButtons(hWnd); /* enable or disable buttons */
  548.                 }
  549.             }
  550.             break;
  551.         case IDM_CLEAR_STATUS:    /* forward to status window            */
  552.             PostMessage(hWndStatus, WM_COMMAND, IDM_CLEAR_STATUS, 0L);
  553.             break;
  554.         case IDM_MAX_STATUS:    /* status windows went to the max    */
  555.         case IDM_RESTORE_STATUS:    /* status windows restored    */
  556.             /* This logic is used for maximizing the message window.
  557.              * It will either hide all other windows allowing the
  558.              * message window to grow, or it will show them,
  559.              * allowing the message box to resume its normal size.
  560.              * These two messages come from the Message window proc.
  561.              */
  562.             {
  563.             int nWndState;    /* ShowWindow state        */
  564.             BOOL bWndEnabled;    /* Enable Window state */
  565.                 
  566.                 if (wParam == IDM_RESTORE_STATUS)
  567.                 {
  568.                     ShowWindow(hWndStatus, SW_RESTORE);
  569.                     UpdateWindow(hWndStatus);
  570.                     bStatusMaxed = FALSE;
  571.                     bWndEnabled = TRUE;
  572.                     nWndState = SW_SHOWNORMAL;
  573.                 }
  574.                 else    /* Message window goes to maximum state        */
  575.                 {
  576.                     bStatusMaxed = TRUE;
  577.                     nWndState = SW_HIDE;    /* assume max state        */
  578.                     bWndEnabled = FALSE;
  579.                 }
  580.                 EnableWindow( hWndHeaderLine1, bWndEnabled);
  581.                 UpdateWindow( hWndHeaderLine1);
  582.                 ShowWindow( hWndHeaderLine1, nWndState);
  583.  
  584.                 EnableWindow( hWndHeaderLine2, bWndEnabled);
  585.                 ShowWindow( hWndHeaderLine2, nWndState);
  586.                 UpdateWindow( hWndHeaderLine2);
  587.  
  588.                 EnableWindow( hWndList, bWndEnabled);
  589.                 UpdateWindow( hWndList);
  590.                 ShowWindow( hWndList, nWndState);
  591.  
  592.                 EnableWindow( hWndTotalLine1, bWndEnabled);
  593.                 ShowWindow( hWndTotalLine1, nWndState);
  594.                 UpdateWindow( hWndTotalLine1);
  595.  
  596.                 EnableWindow( hWndTotalLine2, bWndEnabled);
  597.                 ShowWindow( hWndTotalLine2, nWndState);
  598.                 UpdateWindow( hWndTotalLine2);
  599.  
  600.                 if (wParam == IDM_RESTORE_STATUS) /* uncover buttons    */
  601.                 {
  602.                     UpdateButtons(hWnd);    /* restore to proper state    */
  603.                 }
  604.                 else    /* else Message window occludes buttons            */
  605.                 {
  606.                     EnableWindow( hExtract, bWndEnabled);
  607.                     EnableWindow( hTest, bWndEnabled);
  608.                     EnableWindow( hDisplay, bWndEnabled);
  609.                     EnableWindow( hShowComment, bWndEnabled);
  610.                 }
  611.                 UpdateWindow( hExtract);
  612.                 ShowWindow( hExtract, nWndState);
  613.  
  614.                 ShowWindow( hTest, nWndState);
  615.                 UpdateWindow( hTest);
  616.  
  617.                 ShowWindow( hDisplay, nWndState);
  618.                 UpdateWindow( hDisplay);
  619.  
  620.                 ShowWindow( hShowComment, nWndState);
  621.                 UpdateWindow( hShowComment);
  622.  
  623.                 if (wParam == IDM_MAX_STATUS)    /* message box max'd out */
  624.                 {
  625.                     ShowWindow(hWndStatus, SW_SHOWMAXIMIZED);
  626.                 }
  627.                 SetFocus(hWndStatus); /* pass focus to Messages Window    */
  628.                 SizeWindow(hWnd, FALSE);
  629.             }
  630.             break;
  631.  
  632.         default:
  633.                 return DefWindowProc(hWnd, message, wParam, lParam);
  634.  
  635.  
  636.             break;
  637.               }
  638.             } /* bottom of not in help mode                                */
  639.            break;
  640.        case WM_SETCURSOR:
  641.            /* In help mode it is necessary to reset the cursor in response */
  642.            /* to every WM_SETCURSOR message.Otherwise, by default, Windows */
  643.            /* will reset the cursor to that of the window class. */
  644.  
  645.            if (bHelp) {
  646.                SetCursor(hHelpCursor);
  647.                break;
  648.            }
  649.            return (DefWindowProc(hWnd, message, wParam, lParam));
  650.            break;
  651.  
  652.        case WM_INITMENU:
  653.            if (bHelp) {
  654.                SetCursor(hHelpCursor);
  655.            } 
  656.            return (TRUE);
  657.  
  658.        case WM_ENTERIDLE:
  659.            if ((wParam == MSGF_MENU) && (GetKeyState(VK_F1) & 0x8000)) {
  660.                bHelp = TRUE;
  661.                PostMessage(hWnd, WM_KEYDOWN, VK_RETURN, 0L);
  662.            }
  663.            break;
  664.  
  665.     case WM_CLOSE:                 /* message: close the window    */
  666.         DestroyWindow(hWnd);
  667.  
  668.         break;
  669.  
  670.     case WM_DESTROY:             /* message: destroy the window  */
  671.         DeleteObject(hBrush);         /* delete background brush    */
  672.         WinHelp(hWnd,szHelpFileName,HELP_QUIT,0L);
  673.         PostQuitMessage(NULL);
  674.         break;
  675.  
  676.     default:
  677.         return (DefWindowProc(hWnd, message, wParam, lParam));
  678.     }
  679.     return (NULL);
  680. }
  681.